<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/cpexcel.js"></script> -->
  <script  src="./xlxs.js"></script>
  <style>
    .btn {
      display: inline-block;
      height: 38px;
      line-height: 38px;
      padding: 0 18px;
      background-color: #009688;
      color: #fff;
      white-space: nowrap;
      text-align: center;
      font-size: 14px;
      border: none;
      cursor: pointer;
    }
  </style>
</head>

<body>
  <!-- todo 版本更新之后存在了很大的问题了 -->
  <label id="realBtn" class="btn">
    <input type="file" id="testFile" hidden="hidden">
    上传文件
  </label>
  <script>
    document.querySelector('#testFile').addEventListener('change', function () {
      const file = document.querySelector('#testFile').files[0]
      console.log(file)
      if (file.size > 1024 * 1024) {
        alert('err size is super big')
        return false
      }
      const type = file.name.split('.')
      console.log(type)
      if (type[type.length - 1] !== 'xlsx' && type[type.length - 1] !== 'xls') {
        alert('you only select excel file')
        return false
      }

      const reader = new FileReader()
      reader.readAsBinaryString(file)
      reader.onload = function (e) {
        const data = e.target.result
        const zzexcel = window.XLS.read(data, {
          type: 'binary'
        })
        const result = []
        for (let i = 0; i < zzexcel.SheetNames.length; i++) {
          const newData = windwo.XLS.utils.sheet_to_json(zzexcel.Sheets[zzexcel.SheetNames[i]])
          result.push(...newData)
        }
        console.log(JSON.stringify(result, null, 2))
      }
    })

  </script>

</body>

</html>